/**
 * @create 2022-04-05
 * @desc search table api
 */

import type { BaseResponse } from '@src/types/axios';
import type { AxiosRequestConfig } from 'axios';
import fetcher from '@src/common/utils/axios';

export interface GetSearchTableRequest {
  limit?: number;
  start?: number;
  search?: string;
  jobStatus?: string;
}

interface SearchTableItem1 {
  describe: string;
  hobby: string;
  address: string;
  lastTime: number;
  createTime: number;
}
interface SearchTableItem2 {
  id: string;
  sex: 1 | 2;
  username: string;
  username_en: string;
  experience: '1' | '3' | '5' | '10' | '10+';
  phone: string;
  status: string;
}

export type GetSearchTableRListItem = SearchTableItem1 & SearchTableItem2;

export interface GetSearchTableResponse extends BaseResponse {
  data: {
    total: number;
    list: GetSearchTableRListItem[];
  };
}

export const getSearchTable = (
  params: GetSearchTableRequest,
  config?: AxiosRequestConfig,
): Promise<GetSearchTableResponse> => {
  return fetcher
    .get<GetSearchTableResponse>('/api/search-table', {
      params,
      ...config,
    })
    .then((res) => res.data);
};

export interface GetSearchTableDetailType {
  id: string;
}
export const GetSearchTableDetail = (
  params: GetSearchTableDetailType,
  config?: AxiosRequestConfig,
): Promise<BaseResponse> => {
  return fetcher
    .get<BaseResponse>('/api/search-table/detail', { params, ...config })
    .then((res) => res.data);
};

export interface PostSearchTableType extends SearchTableItem2, Partial<SearchTableItem1> {}
export const postSearchTable = (
  data: PostSearchTableType,
  config?: AxiosRequestConfig,
): Promise<BaseResponse> => {
  return fetcher.post<BaseResponse>('/api/search-table', data, config).then((res) => res.data);
};

export interface DeleteSearchTableItemType {
  ids: string[];
}
export const DeleteSearchTableItem = (
  params: DeleteSearchTableItemType,
  config?: AxiosRequestConfig,
): Promise<BaseResponse> => {
  return fetcher
    .delete<BaseResponse>('/api/search-table', { params, ...config })
    .then((res) => res.data);
};
